// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import GameData_red_blue_man, {emitType} from "./GameData_red_blue_man";
import Music, {musicName} from "../PublicScript/Music";
import ControlScript from "../PublicScript/ControlScript";

const {ccclass, property} = cc._decorator;

@ccclass
export default class ExperienceSkin extends cc.Component {

    @property(sp.Skeleton)
    skinSke: sp.Skeleton[] = [];

    newExperienceSkinIndex = 0;

    // onLoad () {}

    start () {
        this.init();
    }

    init(){
        //获取球一个随机皮肤
        let randNum = Math.round(Math.random() * (GameData_red_blue_man.lockSkinNum.length-1));
        this.skinSke[0].setSkin("red" + GameData_red_blue_man.lockSkinNum[randNum]);
        this.skinSke[1].setSkin("blue" + GameData_red_blue_man.lockSkinNum[randNum]);
        this.newExperienceSkinIndex = GameData_red_blue_man.lockSkinNum[randNum];
        console.log("this.newExperienceSkinIndex:", this.newExperienceSkinIndex);
    }

    onClick(e, d) {
        Music.GamePlayEffect(musicName.click);
        GameData_red_blue_man.showVideo({callback:()=>{
                cc.game.emit(emitType.newSkinExper, this.newExperienceSkinIndex);
                this.node.destroy();
            },name: "游戏中试用皮肤"});
    }

    isDestroy(){
        Music.GamePlayEffect(musicName.click);
        cc.game.emit(emitType.newSkinExper, this.newExperienceSkinIndex, true);
        this.node.destroy();
    }

    useSkin(){
        this.init();
        console.log("this.newExperienceSkinIndex:", this.newExperienceSkinIndex);
        cc.game.emit(emitType.newSkinExper, this.newExperienceSkinIndex);
        this.node.destroy();
    }

    // update (dt) {}
}
